package com.joylight.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.joylight.bean.User;
import com.joylight.dao.UserDao;
import com.joylight.dto.UserDto;
import com.joylight.service.UserService;
import com.joylight.util.CommonUtil;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;
	
	public boolean validate(UserDto userDto) {
		if (userDto != null && !CommonUtil.isEmpty(userDto.getUsername()) && !CommonUtil.isEmpty(userDto.getPassword())) {
			User user = new User();
			BeanUtils.copyProperties(userDto, user);
			List<User> list = userDao.select(user);
			if (list.size() == 1) {
				BeanUtils.copyProperties(list.get(0), userDto);
				return true;
			}
			return false;
		}
		return false;
	}

	@Override
	public boolean register(UserDto userDto) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Set<String> findRoles(String userName) {
		Set<String> roles = new HashSet<String>();
		User user = userDao.getUserByName(userName);
		
		return null;
	}

	@Override
	public User findByUsername(String userName) {
		User user = userDao.getUserByName(userName);
		return null;
	}

	@Override
	public Set<String> findPermissions(String userName) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
